package org.jeecg.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;
import java.util.stream.Stream;

public final class WarehouseConstant {

    /**
     * 仓库区域
     */
    @Getter
    @AllArgsConstructor
    public enum WarehouseTypeEnum {
        PICK("L", "理货区域"),
        ROAD("H", "货道区域"),
        REVIEW("F", "复核区域");

        private final String code;
        private final String define;

        /**
         * 根据code获取对应的define
         *
         * @param code 枚举项的code
         * @return 对应的define，如果找不到则返回null
         */
        public static String getDefineByCode(String code) {
            return Optional.ofNullable(code)
                    .map(c -> Stream.of(values())
                            .filter(e -> e.getCode().equals(c))
                            .findFirst()
                            .orElse(null))
                    .map(WarehouseTypeEnum::getDefine)
                    .orElse(null);
        }
    }

    /**
     * 品番类型
     */
    @Getter
    @AllArgsConstructor
    public enum SkuTypeEnum {
        PT(1, "DICH-PT品"),
        SF(2, "DICH-市贩品");

        private final Integer code;
        private final String define;

        /**
         * 根据code获取对应的define
         *
         * @param code 枚举项的code
         * @return 对应的define，如果找不到则返回null
         */
        public static String getDefineByCode(Integer code) {
            return Optional.ofNullable(code)
                    .map(c -> Stream.of(values())
                            .filter(e -> e.getCode().equals(c))
                            .findFirst()
                            .orElse(null))
                    .map(SkuTypeEnum::getDefine)
                    .orElse(null);
        }
    }

    /**
     * 理货状态
     */
    @Getter
    @AllArgsConstructor
    public enum PickWarehouseStatusEnum {
        CREATE_END("01", "创建完成"),
        RELEASE_END("02", "发布完成"),
        RECEIVE_END("03", "正在拣货"),
        EXECUTE_END("04", "拣货完成"),
        ENTER_ORDER("05", "已创建入库单"),
        DELETE("99", "已被删除");

        private final String code;
        private final String define;

        /**
         * 根据code获取对应的define
         *
         * @param code 枚举项的code
         * @return 对应的define，如果找不到则返回null
         */
        public static String getDefineByCode(String code) {
            return Optional.ofNullable(code)
                    .map(c -> Stream.of(values())
                            .filter(e -> e.getCode().equals(c))
                            .findFirst()
                            .orElse(null))
                    .map(PickWarehouseStatusEnum::getDefine)
                    .orElse(null);
        }
    }

    /**
     * 入库状态
     */
    @Getter
    @AllArgsConstructor
    public enum EnterWarehouseStatusEnum {
        CREATE_END("01", "创建完成/未发布"),
        RELEASE_END("02", "发布完成/已发布"),
        RECEIVE_END("03", "领取完成/正在执行"),
        EXECUTE_END("04", "执行完成/任务已完成"),
        FORCE_END("05", "执行完成/任务已完成"),
        DELETE("99", "已被删除");

        private final String code;
        private final String define;
    }

    /**
     * 出库状态
     * out_order、out_order_task_main表中status字段
     */
    @Getter
    @AllArgsConstructor
    public enum OutWarehouseStatusEnum {
        CREATE_END("01", "未发布"),
        RELEASE_END("02", "已发布"),
        RECEIVE_END("03", "执行中"),
        EXECUTE_END("04", "执行完成"),
        REVIEW_END("06", "复核完成"),
        DELETE("99", "已被删除");

        private final String code;
        private final String define;

        /**
         * 根据code获取对应的define
         *
         * @param code 枚举项的code
         * @return 对应的define，如果找不到则返回null
         */
        public static String getDefineByCode(String code) {
            return Optional.ofNullable(code)
                    .map(c -> Stream.of(values())
                            .filter(e -> e.getCode().equals(c))
                            .findFirst()
                            .orElse(null))
                    .map(OutWarehouseStatusEnum::getDefine)
                    .orElse(null);
        }
    }
}
